package com.wanxi;

import com.wanxi.model.StudentModel;

import java.util.ArrayList;
import java.util.Arrays;

public class MyArrayList {
    public static void main(String[] args) {
        ArrayList list = new ArrayList();
        list.add(1);
        list.add("a");
        list.add(true);
        list.add(new int[1]);
        String[] aa = {};
        int[] bb = {};
        ArrayList<Integer> arrayList = new ArrayList<>();
        arrayList.add(1);
        arrayList.add(2);
        arrayList.add(3);
        arrayList.add(4);
        arrayList.add(5);
        arrayList.add(2, 15);

//        arrayList.add(true);
//        如果能够直接打印，则重写了父类的toString方法
//        如果没有父类，则重写了Object的toString方法
        System.out.println(arrayList);
//        Arrays.toString();

        arrayList.remove(1);
        System.out.println(arrayList);
        ArrayList<StudentModel> studentModelArrayList = new ArrayList<>();
        StudentModel model = new StudentModel("张三2", 232);

        studentModelArrayList.add(new StudentModel("张三1", 231));
//        studentModelArrayList.add(new StudentModel("张三2", 232));
        studentModelArrayList.add(model);
        studentModelArrayList.add(new StudentModel("张三3", 233));
        studentModelArrayList.add(new StudentModel("张三4", 234));
        System.out.println(studentModelArrayList);
//        studentModelArrayList.remove(model);
//        System.out.println(studentModelArrayList);
        System.out.println(studentModelArrayList.size());

        studentModelArrayList.remove(2);
        studentModelArrayList.set(1, new StudentModel("张三5", 255));
        System.out.println(studentModelArrayList);
        System.out.println(studentModelArrayList.size());
        StudentModel model1 = studentModelArrayList.get(2);
//        System.out.println(model1);
//        如果要遍历集合，则通过get拿值
        for (int i = 0; i < studentModelArrayList.size(); i++) {
            System.out.println(studentModelArrayList.get(i));
        }
    }
}
